<?php
/**
 * Created by PhpStorm.
 * User: maxl
 * Date: 2017/4/22
 * Time: 16:35
 * 注册添加offerSkill表
 */

header("Content-Type: text/plain;charset=utf-8");
header("Access-Control-Allow-Origin:*");
header("Access-Control-Methods:POST,GET");

//载入register.php类
require_once ("classes/register.php");
require_once ("classes/user.php");

//接受前台数据
$name = isset($_POST['name']) ? $_POST['name'] : '';                        //用户名
$offerState = isset($_POST['offerState']) ? $_POST['offerState'] : '';      //用户提供技能帮助状态
$offerSkill = isset($_POST['offerSkill']) ? $_POST['offerSkill'] : '';      //用户提供帮助技能
//$QQ = isset($_POST['QQ']) ? $_POST['QQ'] : '';

//实例化
$selectId = new User();
$result5 = $selectId -> insertId($name);              //result5：用户的ID
//$result6 = mysqli_fetch_assoc($result5);
echo $result5;
//$result5= 3;
$insertRegister = new Register();
$result2 = $insertRegister -> insertSkillOffer($result5,$offerSkill,$offerState);           //result2：插入到skillOffer表中

//异常处理
if (!$result5){
    $id = "";
} else if(!$result2){
    $id = "";
} else{
    $selectName = new User();
    $result3 = $selectName -> selectName($name);            //result3：判断数据库里有没有此用户名
    if ($result3 = '0'){
        $id = $result5;
    } else{
        $id = "";
    }
}

echo json_encode($id,JSON_UNESCAPED_UNICODE);

?>